<?php

/**
 * @author 	Samuel Carlier
 * @package P3Base_Base
 */
class P3Base_Base_Debugger {

	/**
	 * return debugging information
	 */
	const MODE_RETURN = 1;

	/**
	 * Directly display debugging information
	 */
	const MODE_DISPLAY = 2;

	/**
	 * Disable Debugging
	 */
	const MODE_DISABLED = 0;

	/**
	 * Set debugging mode only for read
	 */
	const TYPE_READ = 1;

	/**
	 * Set debugging mode only for write
	 */
	const TYPE_WRITE = 2;
	
	/**
	 * Set debugging mode for read and writeing
	 */
	const TYPE_READ_WRITE = 3;
	
	/**
	 * @var int
	 */
	private $_type = 0;

	/**
	 * @var int
	 */
	private $_mode = 0;
	
	/**
	 * @var string
	 */
	private $_content = '';
	
	/**
	 * @param int $mode
	 * @param int $type
	 */
	public function __construct($type=self::TYPE_READ_WRITE, $mode=self::MODE_DISPLAY) {
		$this->setType($type); 
		$this->setMode($mode);
	}

	/**
	 * Set type for debugging
	 * 
	 * @param int $type possible constants are 
	 * 					MODE_RETURN, MODE_DISABLE, MODE_DISABLED
	 */
	public function setType($type) {
		$this->_type = $type;
	}

	/**
	 * Set mode for debugging
	 * 
	 * @param int $mode possible constants are
	 * 					TYPE_WRITE, TYPE_READ (use it as bits)
	 */
	public function setMode($mode) {
		$this->_mode = $mode;
	}
	
	/**
	 * @return int
	 */
	public function getType() {
		return $this->_type;	
	}
	
	/**
	 * @return int
	 */
	public function getMode() {
		return $this->_mode;	
	}
	
	/**
	 * @param  int $type
	 * @return bool
	 */
	public function isType($type) {
		if($this->_type === self::TYPE_READ_WRITE) {
			return true;	
		}
		
		if($type === $this->_type) {
			return true;	
		}
		
		return false; 
	}

	/**
	 * @param  int $mode
	 * @return bool
	 */
	public function isMode($mode) {
		if($mode === $this->_mode) {
			return true;	
		}
		
		return false; 
	}

	/**
	 * @param string $content
	 */
	public function appendDebug($content) {
		if($this->isMode(self::MODE_DISPLAY)) {
			echo htmlspecialchars($content);
		}

		$this->_content .= $content;	
	}

	/**
	 * @return string
	 */
	public function __toString() {
		return $this->_content;	
	}
}

?>